-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tag remove preprocessor #640
Conversation
9eb211f
to
447f99c
Compare
nbconvert/preprocessors/tagremove.py
Outdated
|
||
remove_cell_tags = List(Unicode, default_value=[]).tag(config=True) | ||
remove_all_outputs_tags = List(Unicode, default_value=[]).tag(config=True) | ||
remove_single_output_tags = List(Unicode, default_value=[]).tag(config=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the order doesn't matter here, I think you could make them sets instead of lists. That means we can use set operations to check if any tag matches:
self.remove_cell_tags.intersection(cell.get('metadata', {}).get('tags', []))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
nbconvert/preprocessors/tagremove.py
Outdated
if 'metadata' in cell: | ||
for field in self.remove_metadata_fields: | ||
cell.metadata.pop(field, None) | ||
if cell.get('outputs', {}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really matter to the code, but for the sake of clarity, I'd make the fallback value a list rather than a dict. Or maybe even None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
nbconvert/preprocessors/tagremove.py
Outdated
|
||
def preprocess_output(self, output, resources, | ||
cell_index, output_index): | ||
return output, resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you planning some future extension here, or can this method be discarded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was partially trying to give people a handle on preprocessing individual outputs if they wanted to subclass (I thought it might be helpful for things like tag based preprocessing… but I'm realising now that something like that is more broad ranging and should probably be put into a different PR).
This basically looks good, I've just noted a few places where I think the code can be clearer/simpler. :-) |
Should we be considering a major release soon? I want to add a new class to handle the input version of this, so maybe we should have it target 6.0? |
Historically with IPython we did feature releases like '6.0' and bugfix rollups like '6.1', but since the big split we've tended more towards semver style versioning, so we increment the major version to indicate breaking changes. To some extent this is up to the people working on each individual project, though. I'm not the biggest fan of semver - I think it ignores the complexity of real development, where almost every change can break something - but I know that when we're aiming for a new .0 release, it tends to become a Big Deal, and everyone wants their thing backported to the previous series. So I'm inclined to leave 6.0 until we actually want to break something. |
K @takluyver would you say this is good to go? |
This PR implements tag based element filtering using a Preprocessor to remove entire cells, entire output areas, and individual outputs.
Cell removal is enabled by adding a tag to
tags
in the cell'smetadata
and then adding the tag toTagRemovePreprocessor.remove_cell_tags
.Output area removal is enabled by adding a tag to
tags
in the cell'smetadata
and then adding the tag toTagRemovePreprocessor.remove_all_outputs_tags
.Individual output removal is enabled by adding a tag to a
tags
field created in an output'smetadata
, and then adding the tag toTagRemovePreprocessor.remove_single_output_tags
.I have an idea talked through with @Carreau on how to additionally filter inputs (which would create invalid notebook objects), but that can't be done with a preprocessor (since preprocessors can only produce valid notebooks). Therefore, I'll leave that to another PR.